package implementations.dm_kernel.server;

import implementations.dm_kernel.Server;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

import commom.GenericConsumer;
import commom.GenericResource;

public class MainServer extends Server{
	
	private Map<String,String[]> globalVarSlaves, slaves;
	private List<String> slavesIDs;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		// Read properties file.
		Properties properties = new Properties();
		try {
		    properties.load(new FileInputStream("../jcl_conf/config.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		int serverPort = Integer.parseInt(properties.getProperty("serverMainPort"));
		MainServer m = new MainServer(serverPort);
	}
	
	public MainServer(int port){
		super(port);
		globalVarSlaves = new TreeMap<String, String[]>();
		slavesIDs = new LinkedList<String>();
		slaves = new TreeMap<String, String[]>();	
		
		System.err.println("JCL server ok!");
		
		this.begin();
				
	}

	@Override
	protected void beforeListening() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void duringListening() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected GenericConsumer<Socket> createSocketConsumer(
			GenericResource<Socket> r) {
		// TODO Auto-generated method stub
		return new implementations.dm_kernel.server.SocketConsumer<Socket>(r, globalVarSlaves, slavesIDs, slaves);
	}

}
